from modules.amis.component.base import FormMode, Level, ActionType
from modules.amis.component.datainput import Form, InputText, InputPassword
from modules.amis.component.function import Button
from modules.amis.component.layout import Page


def classic_login_page_build(login_api: str):
    login_form = Form(name="loginInfo", title={
        "type": "tpl",
        "tpl": "用户登录",
        "className": "inline-block w-full text-center font-bold text-md",
        "autoFill.silent": False
    })
    login_form.wrapWithPanel = False
    login_form.mode = FormMode.horizontal
    login_form.api = login_api

    username = InputText(name="username", placeholder="请输入用户名", label=False, clearable=True)
    # username.value = "abc"
    username.validations = {
        "isRequired": True
    }
    username.validationErrors = {
        "isRequired": "用户名不能为空"
    }

    password = InputPassword(name="password", placeholder="请输入密码", label=False, clearable=True, required=True)
    # password.value = "123456"
    password.validations = {
        "isRequired": True
    }
    password.validationErrors = {
        "isRequired": "密码不能为空"
    }

    submit_button = Button(label="登录", level=Level.primary, actionType=ActionType.submit,
                           # redirect="/"
                           )
    submit_button.block = True

    register_button = Button(label="免费注册", level=Level.link, actionType=ActionType.url)
    register_button.className = "text-gray text-sm"

    forget_button = Button(label="忘记密码", level=Level.link, actionType=ActionType.url)
    forget_button.className = "text-gray text-right text-sm"

    login_form.body = [
        username,
        password,
        submit_button,
        register_button,
        forget_button
    ]

    # button_area = Container(body=[
    #     submit_button,
    #     Container(body=[
    #             register_button,
    #             forget_button,
    #         ],
    #         bodyClassName="p-0"
    #     ),
    # ],
    #     className="h-auto mt-6",
    #     bodyClassName="p-0"
    # )

    return Page(body=[
        login_form,
        # button_area,
    ],
        className="border-solid border-gray-300 border rounded p-4 w-1/3 min-w-sm mx-auto h-auto mt-40"
    ).render()
